﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Derbster.Domain
{
    public class Official : IEquatable<Official>
    {
        [ContractVerification(false)]
        internal Official()
        {
            
        }
        public Official(string name)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Name = name;
        }

        public Official(string name, string number)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(!string.IsNullOrWhiteSpace(number));
            Contract.Requires(number.Length > 0 && number.Length <= 4);
            Contract.Requires(Regex.IsMatch(number, "[a-zA-Z0-9]+"));
            Name = name;
            Number = number;
        }
        [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        
        public int OfficialId { get; internal set; }
        public League League { get; internal set; }
        public string Name { get; internal set; }
        public string Number { get; internal set; }
        public string Email { get; internal set; }
        public Guid GlobalIdentifier { get; internal set; }
        
        public bool Equals(Official other)
        {
            if (other == null) return false;
            return this.OfficialId == other.OfficialId;
        }
    }
}
